package com.wifi.channel.servlet;

import com.alibaba.fastjson.JSON;
import com.wifi.channel.service.ChannelService;
import com.wifi.channel.service.ChannelServiceImpl;
import com.wifi.unti.PageInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/channel")
public class ChannelServlet extends HttpServlet {
ChannelService channelService=new ChannelServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("WEB-INF/channel/channelM.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNum=request.getParameter("pageNum");
        String pageSize=request.getParameter("pageSize");
        String class1id=request.getParameter("class1id");
        String class2id=request.getParameter("class2id");
        String title=request.getParameter("title");

        long totalNum =channelService.selectCount(class1id,class2id,title);

        PageInfo pageInfo = new PageInfo(pageNum,pageSize,(int)totalNum );

        List<Object> menuPage=channelService.getChannel(pageInfo.getStart(),pageInfo.getPageSize(),class1id,class2id,title);
        pageInfo.setList(menuPage);
        System.out.println(JSON.toJSONString(pageInfo));
        response.getWriter().write(JSON.toJSONString(pageInfo));
    }


}
